from cgi import print_directory
import openpyxl

wb = openpyxl.load_workbook(r"F:\my_profile\study\code_pub\study_code_pub\python表格\test1.xlsx")

sheet1 = wb.active

print(sheet1.merged_cell_ranges)


for merged_range in sheet1.merged_cell_ranges:  # 循环查找该单元格所属的合并区域
    # 判断是纵向的单元格
    if merged_range.size["columns"] == 1:
        _str = merged_range.coord.replace("A","E")
        # 获取值并相加
        ws = sheet1[_str]
        num = 0
        for row in ws: # 行
            res = row[0].value
            if isinstance(res,int) and res != 0:
                num += row[0].value
        print(sheet1[merged_range.coord.split(":")[0]].value,num)

        